/*
 *
 *                     .::::.
 *                   .::::::::.
 *                  :::::::::::  by qssq666@foxmail.com
 *              ..:::::::::::'
 *            '::::::::::::'
 *              .::::::::::
 *         '::::::::::::::..
 *              ..::::::::::::.
 *            ``::::::::::::::::
 *             ::::``:::::::::'        .:::.
 *            ::::'   ':::::'       .::::::::.
 *          .::::'      ::::     .:::::::'::::.
 *         .:::'       :::::  .:::::::::' ':::::.
 *        .::'        :::::.:::::::::'      ':::::.
 *       .::'         ::::::::::::::'         ``::::.
 *   ...:::           ::::::::::::'              ``::.
 *  ```` ':.          ':::::::::'                  ::::..
 *                     '.:::::'                    ':'````..
 *
 */

package com.ggh.jinjilive.views.live.gift.adapter;

import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.Glide;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.views.live.gift.bean.GiftDemoModel;
import com.ggh.jinjilive.views.live.gift.interfacei.GiftModelI;
import com.ggh.jinjilive.views.live.gift.interfacei.UserInfoI;
import com.ggh.jinjilive.views.live.gift.periscope.GiftAnimLayout;
import com.ggh.jinjilive.views.live.gift.ui.StrokeTextView;


/**
 * 不设置本方法则内部维护一系列
 * Created by qssq on 2017/7/7 qssq666@foxmail.com
 */

public class GiftBarAdapter implements GiftAnimLayout.GiftCallBack {


    private static final String TAG = "GiftBarAdapter";

    @Override
    public void onGiftAnimOver(GiftModelI giftModel) {
        ((GiftDemoModel) giftModel).setShowcount(0);//如果是0则会直接设置为1的
        Log.w(TAG, "onGiftAnimOver:" + giftModel);
    }

    @Override
    public void onFindExistGiftAnim(GiftModelI giftModel) {
//                ((GiftModel) giftModel).setShowcount(1);
        Log.w(TAG, "onFindExistGiftAnim:" + giftModel);

    }

    @Override
    public void onAddNewGift(GiftModelI giftModel) {
        Log.w(TAG, "onAddNewGift:" + giftModel);

    }

    @Override
    public void onAddWaitUnique(GiftModelI giftModel) {
        Log.w(TAG, "onAddWaitUnique:" + giftModel);

    }

    @Override
    public int onRequestShowGiftCount(GiftModelI modelI, StrokeTextView tvValue) {
        int showcount = ((GiftDemoModel) modelI).getShowcount();//如果一直返回0还是由内部支持
//                showcount = showcount == 0 ? tvValue.getValue() + 1 : showcount;
        Log.w(TAG, "onRequestShowGiftCount :showCount:" + showcount);
//                showcount = showcount == 0 ? tvValue.getValue() + 1 : showcount;
        return showcount;
    }

    @Override
    public ViewGroup getGiftLayout(GiftAnimLayout giftAnimLayout) {
        //返回null表示内部本来就有的那个
        return (ViewGroup) LayoutInflater.from(giftAnimLayout.getContext()).inflate(R.layout.layout_gift_view, giftAnimLayout, false);
    }

    /**
     * 返回false表明内部进行绑定图片 那么这里就没必要再进行处理了。但是这里要维护的话头像也给维护了哈!
     *
     * @param userInfo
     * @param giftModel
     * @param giftHolder
     * @return
     */
    @Override
    public boolean onBindPic(UserInfoI userInfo, GiftModelI giftModel, GiftAnimLayout.GiftHolder giftHolder) {
        Glide.with(giftHolder.ivFace).load(userInfo.getFace()).into(giftHolder.ivFace);
        Glide.with(giftHolder.ivGift).load(giftModel.getGiftImage()).into(giftHolder.ivGift);
        return true;
    }
}
